package com.bocloud.cmp.driver.providers.impl;

import org.springframework.stereotype.Service;

import com.bocloud.cmp.driver.config.Configuration;
import com.bocloud.cmp.driver.providers.AlarmDriver;
import com.bocloud.cmp.driver.providers.intf.AlarmProvider;
import com.bocloud.cmp.driver.providers.vmware.VmwareAlarmDriver;
import com.bocloud.cmp.driver.utils.VendorConverter;
import com.bocloud.cmp.enums.VendorType;
import com.bocloud.cmp.model.Butler;
import com.bocloud.common.model.BsmResult;

/**
 * 告警操作服务接口实现类
 * 
 * @author weiwei
 *
 */
@Service("alarmProvider")
public class AlarmProviderImpl implements AlarmProvider {

	@Override
	public BsmResult list(String vendor, String region) {
		AlarmDriver driver = null;
		Butler butler = Configuration.instance().getConfig(vendor);
		VendorType type = VendorConverter.convert(butler.getCategory());
		switch (type) {
		case OPENSTACK:
			//driver = new OSAlarmDriver(butler.getUrl(), butler.getUsername(), butler.getPassword(), butler.getTenant(),
				//	butler.getDomainName(), butler.getProjectName(), Version.valueOf(butler.getVersion()));
			break;
		case VMWARE:
			driver = new VmwareAlarmDriver(butler.getUrl(), butler.getUsername(), butler.getPassword());
			break;
		default:
			break;
		}
		if (null == driver) {
			return new BsmResult(false, "暂不支持！");
		} else if (!driver.accessable()) {
			return new BsmResult(false, "用户鉴权失败！");
		} else {
			return driver.sync();
		}
	}
}
